import pygal
from die import Die


# 创建1个D6骰子、1个D10骰子
die_1 = Die(6)
die_2 = Die(10)


# 投掷若干次骰子，并将结果（点数）存储在一个列表中
results = []
results_1 = []
results_2 = []

for i in range(50000):
    LV_result_1 = die_1.roll()
    LV_result_2 = die_2.roll()
    LV_result = LV_result_1 + LV_result_2

    results_1.append(LV_result_1)
    results_2.append(LV_result_2)
    results.append(LV_result)

# print(results)


# 统计结果
# D6 + D10 的结果
frequencies = []
max_result = die_1.num_sides + die_2.num_sides
for value in range(2, max_result+1):
    frequency = results.count(value)
    frequencies.append(frequency)
print(frequencies)

# D6 的结果
frequencies_1 = []
for value in range(1, die_1.num_sides+1):
    frequency_1 = results_1.count(value)
    frequencies_1.append(frequency_1)
print(frequencies_1)

# D10 的结果
frequencies_2 = []
for value in range(1, die_2.num_sides+1):
    frequency_2 = results_2.count(value)
    frequencies_2.append(frequency_2)
print(frequencies_2)


# 可视化结果
INS_hist = pygal.Bar()

INS_hist.title = "Results of rolling a D6 and a D10 50,000 times"
INS_hist.x_labels = [x for x in range(2, max_result+1)]
INS_hist.x_title = "Result"
INS_hist.y_title = "Frequency"

INS_hist.add("D6 + D10", frequencies)
INS_hist.add("D6", frequencies_1)
INS_hist.add("D10", frequencies_2)
INS_hist.render_to_file("different_dice.svg")
